package DP;

/**
 * @author 曹见朋
 * @create 2024-06-12-21:17
 */
public class Main416 {
    // TODO 416. 分割等和子集
    public static boolean canPartition(int[] nums) {
        int sum = 0;
        for(int num : nums){
            sum += num;
        }
        if(sum % 2 != 0) return false;
        sum /= 2;
        int[] dp = new int[sum + 1];

        for(int i = 0; i < nums.length; i++){
            for(int j = sum; j >= nums[i]; j--){
                dp[j] = Math.max(dp[j], dp[j - nums[i]] + nums[i]);
            }
        }

        for(int i = 0; i <= sum; i++){
            System.out.print(" " + dp[i]);
        }

        return dp[sum] == sum;
    }

    public static void main(String[] args) {
        int[] nums = new int[]{2,2,3,4,5,6};
        boolean b = canPartition(nums);
        System.out.println(b);
    }
}
